ARG NUCLIO_LABEL=1.13.8
ARG NUCLIO_ARCH=amd64
ARG DEBIAN_FRONTEND=noninteractive
ARG NUCLIO_BASE_IMAGE=pytorch/pytorch:1.13.1-cuda11.6-cudnn8-runtime
ARG NUCLIO_ONBUILD_IMAGE=quay.io/nuclio/handler-builder-python-onbuild:${NUCLIO_LABEL}-${NUCLIO_ARCH}
FROM nuclio/uhttpc:0.0.1-amd64 as uhttpc

FROM ${NUCLIO_ONBUILD_IMAGE} as processor
FROM ${NUCLIO_BASE_IMAGE} as baseimage
# Copy required objects from the suppliers
COPY --from=processor /home/nuclio/bin/processor /usr/local/bin/processor
COPY --from=processor /home/nuclio/bin/py /opt/nuclio/
COPY --from=processor /home/nuclio/bin/py*-whl/* /opt/nuclio/whl/
COPY --from=uhttpc /home/nuclio/bin/uhttpc /usr/local/bin/uhttpc
RUN pip3 config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
RUN python3 -m pip install --upgrade pip \
 && python3 -m pip install nuclio-sdk msgpack --no-index --find-links /opt/nuclio/whl

ENV CUDA_HOME=/usr/local/cuda

ENV TZ=Asia/Shanghai

#设置时区
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo '$TZ' > /etc/timezone


RUN  sed -i s@/archive.ubuntu.com/@/mirrors.aliyun.com/@g /etc/apt/sources.list
RUN apt-get -y update && apt-get install -y --no-install-recommends \
         build-essential \
         python3-opencv \
         ca-certificates && \
    rm -rf /var/lib/apt/lists/*

# 更新 conda
COPY ./conda  /root
RUN conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
RUN conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
RUN conda config --set show_channel_urls yes
RUN cd /root && conda install nsight-compute-2024.1.1.4-h968f9c8_2.conda tesseract-5.2.0-h6a678d5_0.conda gds-tools-1.9.1.3-h99ab3db_1.conda cuda-nsight-12.4.127-h06a4308_1.conda
RUN conda update conda -y
RUN conda install nvidia/label/cuda-11.6.1::cuda
COPY ./requirements.txt ./
RUN pip install -r requirements.txt

WORKDIR /root
COPY ./huggingface/hub/  .cache/huggingface/hub/
# Set the working directory for all the subsequent Dockerfile instructions.
WORKDIR /opt/nuclio

COPY ./GroundingDINO /opt/nuclio


ENV PATH=/usr/local/cuda/bin:$PATH
RUN apt install nvidia-cuda-dev

RUN pip install numpy==1.23 && cd /opt/nuclio && pip install -e .


CMD [ "processor" ]

